package com.lvyq.javaprint.controller;

import com.lvyq.javaprint.common.CommonResult;
import com.lvyq.javaprint.context.PrintContext;
import com.lvyq.javaprint.factory.PrintServiceFactory;
import com.lvyq.javaprint.model.PrintData;
import com.lvyq.javaprint.service.PrintService;
import com.lvyq.javaprint.util.PrintUtils;
import com.lvyq.javaprint.ws.WebSocketServer;
import org.springframework.web.bind.annotation.*;
import java.net.MalformedURLException;


/**
 * @author lvyq 打印
 * @version 1.0
 * Create by 2024-04-24 9:18
 */
@RestController
@RequestMapping("/print")
@CrossOrigin
public class PrintController {



    @GetMapping("/getPath/{sessionId}")
    public void getPath(@PathVariable("sessionId") String sessionId){
        String property = System.getProperty("user.dir");
        WebSocketServer.SendMessageById(property,sessionId);
    }


    /** 单个打印
     * @description
     * @author lvyq
     * @param[1] file
     * @param[2] data
     * @throws
     * @return CommonResult
     * @time 2024-08-06 16:27
     */
    @RequestMapping("/single")
    public CommonResult printSingle(PrintData data) throws MalformedURLException {
            PrintContext printContext = new PrintContext();
            PrintService printService = PrintServiceFactory.getPrintService(data.getType());
            printContext.setPrintService(printService);
            //打印处理
            PrintUtils.handlePrintContext(printContext,data);
            return CommonResult.success();
    }



}
